import threading
from threading import Condition

class XiaoAi(threading.Thread):
    def __init__(self,cond):
        super().__init__(name="小爱")
        self.condition = cond

    def run(self):
        with self.condition:
            self.condition.wait()
            print("{}:在".format(self.name))
            self.condition.notify()
            self.condition.wait()
            for i in range(10):
                print("{}:{}".format(self.name, i))
                self.condition.notify()
                self.condition.wait()

class TianMao(threading.Thread):
    def __init__(self,cond):
        super().__init__(name="天猫")
        self.condition = cond
    def run(self):
        with self.condition:
            print("{}:小爱同学".format(self.name))
            self.condition.notify()
            self.condition.wait()

            for i in range(10):
                print("{}:{}".format(self.name,i))
                self.condition.notify()
                self.condition.wait()


if __name__ == '__main__':
    cond = Condition()
    a = XiaoAi(cond)
    b=TianMao(cond)

    a.start()
    b.start()





